package cn.zhang.reimbursement_1.controller;

import cn.zhang.reimbursement_1.model.Reimburse;
import cn.zhang.reimbursement_1.service.ReimburseService;
import cn.zhang.reimbursement_1.tools.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping("/admin/reimburse")
@Api(tags = "审批模块")
public class ReimburseController {
    @Autowired
    private ReimburseService reimburseService;


    @ApiOperation("添加申请记录")
    @PostMapping("/save_reimburse")
    public JsonData saveReimburse(@RequestBody Reimburse reimburse){
        JsonData jsonData  = reimburseService.saveReimburse(reimburse);
        return jsonData;
    }


    @ApiOperation("分页查询申请记录")
    @GetMapping("/page_get_reimburse")
    public JsonData pageGetReimburse(@RequestParam(value = "pageSize",defaultValue = "10",required = false) int pageSize
            ,@RequestParam(value = "pageNum",defaultValue = "1",required = false) int pageNum
            ,@RequestParam(value = "like",defaultValue = "",required = false)String like){
        JsonData jsonData = reimburseService.pageGetReimburse(pageNum,pageSize,like);
        return jsonData;
    }


    @ApiOperation("通过审批")
    @GetMapping("/pass_reimburse")
    public JsonData passReimburse(@RequestParam long id){
        JsonData jsonData = reimburseService.passReimburse(id);
        return jsonData;
    }

    @ApiOperation("未通过审核")
    @GetMapping("/un_pass_reimburse")
    public JsonData unPassReimburse(@RequestParam long id,@RequestParam String reason){
        JsonData jsonData =reimburseService.unPassReimburse(id,reason);
        return jsonData;
    }

    @ApiOperation("查询两个日期出差次数")
    @GetMapping("/get_two_time_count")
    public JsonData getTwoTimeCount(@RequestParam(value = "start",required = false,defaultValue = "")String start,
                                    @RequestParam(value = "end",required = false,defaultValue = "")String end) throws ParseException {
        JsonData jsonData = reimburseService.getTwoTimeCount(start,end);
        return jsonData;
    }


    @ApiOperation("员工确认")
    @GetMapping("/confirm")
    public JsonData confirm(@RequestParam long id){
        JsonData jsonData = reimburseService.confirm(id);
        return  jsonData;
    }
}
